<template>
    <div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>单位名称</label>
            </div>
            <div class="equipment-right-select"
                 @click="companyPropShow = true"
                 v-if="userInfo.departsir != '1'">
                <span>{{departObj.Name?departObj.Name:'请选择'}}</span>
                <i class="iconfont icon-jinru rightmsg"></i>
            </div>
            <div class="equipment-right-select"
                 v-else>
                <span>{{departObj.Name}}</span>
            </div>
        </div>
        <div class="form-item  form-item-style1">
            <div class="label-title">
                <label>开始时间</label>
            </div>
            <group>
                <datetime v-model="startTime"
                          @on-change="onPullingDown"></datetime>
            </group>
        </div>
        <div class="form-item  form-item-style1">
            <div class="label-title">
                <label>结束时间</label>
            </div>
            <group>
                <datetime v-model="endTime"
                          @on-change="onPullingDown"></datetime>
            </group>
        </div>
        <h2>监测次数: {{listAllCount}}次</h2>
        <noData v-if="listAllCount == 0"></noData>
        <div class="bscroll">
            <vue-better-scroll class="wrapper"
                               ref="scroll"
                               :scrollbar="scrollbarObj"
                               :pullDownRefresh="pullDownRefreshObj"
                               :pullUpLoad="pullUpLoadObj"
                               :startY="parseInt(startY)"
                               @pullingDown="onPullingDown"
                               @pullingUp="onPullingUp">
                <div class="bscroll-container">
                    <ul class="lists">
                        <li v-for="(item,index) in list"
                            :key="index">
                            <router-link :to="{path:'/monitoringRecordDetail',query:{id:item.ID}}">
                                <div>
                                    <h5>{{item.OccHealthHarm}}</h5>
                                    <p>{{item.StaterCheckDate?item.StaterCheckDate.split(' ')[0]:''}}</p>
                                </div>
                                <div class="status">
                                    <span :class="{'blue':item.IsCb == '合格','orange':item.IsCb == '合格'}">【{{item.IsCb}}】</span>
                                    <x-icon type="ios-arrow-right"
                                            size="20"
                                            class="icon-right"></x-icon>
                                </div>
                            </router-link>
                        </li>
                    </ul>
                </div>
            </vue-better-scroll>
        </div>
        <companyProp :companyPropShow="companyPropShow"
                     :selectCompany="selectCompany"
                     business="GetHdProjectsAndFb"></companyProp>
        <myMenu addPath="/addMonitoring"
                ref="myMenu"></myMenu>
    </div>
</template>
<script>
import formatDate from '@/utils/formatDate'
import { TransferDom, Popup } from 'vux'
import myMenu from '@/commonComponents/menu'
import VueBetterScroll from 'vue2-better-scroll'
import companyProp from '@/commonComponents/companyProp'
export default {
    name: 'record',
    directives: {
        TransferDom
    },
    components: {
        Popup,
        myMenu,
        VueBetterScroll,
        companyProp
    },
    data () {
        return {
            // dropDown: false
            // 这个配置可以开启滚动条，默认为 false。当设置为 true 或者是一个 Object 的时候，都会开启滚动条，默认是会 fade 的
            scrollbarObj: {
                fade: true
            },
            // 这个配置用于做下拉刷新功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启下拉刷新，可以配置顶部下拉的距离（threshold） 来决定刷新时机以及回弹停留的距离（stop）
            pullDownRefreshObj: {
                threshold: 90,
                stop: 40
            },
            // 这个配置用于做上拉加载功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启上拉加载，可以配置离底部距离阈值（threshold）来决定开始加载的时机
            pullUpLoadObj: {
                threshold: 0,
                txt: {
                    more: '加载更多',
                    noMore: '没有更多数据了'
                }
            },
            startY: 0, // 纵轴方向初始化位置
            scrollToX: 0,
            scrollToY: 0,
            scrollToTime: 700,
            pageIndex: 0,
            list: [],
            listAllCount: 0,
            listCount: 0,
            companyPropShow: false,
            startTime: `${formatDate().split('-')[0]}-01-01`,
            endTime: formatDate(),
            departObj: {
                Name: '',
                Id: ''
            },
            userInfo: {}
        }
    },
    created () {
        this.userInfo = JSON.parse(localStorage.getItem('userInfo'))
        this.departObj.Name = this.userInfo.deptname
        this.departObj.Id = this.userInfo.deptid
    },
    activated () {
        this.$refs.myMenu.flag = false
    },
    mounted () {
        this.onPullingDown()
    },
    methods: {
        onPullingDown () {
            this.pageIndex = 0
            this.list = []
            this.getData()
        },
        onPullingUp () {
            this.pageIndex++
            this.getData()
        },
        selectCompany (item) {
            this.companyPropShow = false
            this.departObj = item
            this.onPullingDown()
        },
        getData () {
            let params = {
                'business': 'GetOccHealthSup',
                'data': {
                    'BusinessType': '1', // 1: 职业病危害因素查询
                    'EndDate': this.endTime,
                    'StartDate': this.startTime,
                    'departId': this.departObj.Id
                },
                'pageIndex': this.pageIndex,
                'pageSize': 10,
                'userId': this.userInfo.userid
            }

            this.$axiosAjax.getConfigJson(params)
                .then((res) => {
                    if (res.data.code === 0) {
                        this.list = this.list.concat(res.data.data)
                        this.listAllCount = res.data.count
                        this.listCount = this.list.length
                    }
                    if (this.listCount < this.listAllCount) {
                        this.$refs.scroll.forceUpdate(true)
                    } else {
                        this.$refs.scroll.forceUpdate(false)
                    }
                }).catch((response) => {
                })
        }
    }
}
</script>
<style scoped>
h2 {
    width: 100%;
    height: 40px;
    line-height: 40px;
    text-align: right;
    padding-right: 20px;
    box-sizing: border-box;
    background: #ebeef2;
}
.bscroll {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    top: 265px;
    overflow: hidden;
}
.lists {
    padding-left: 20px;
}
.lists a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px 14px 0;
    border-bottom: 1px solid #efeff4;
}
.lists h5 {
    line-height: 18px;
    color: #333;
    font-size: 13px;
    font-weight: 700;
}
.lists p {
    font-size: 14px;
    color: #999;
    line-height: 18px;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.status {
    display: flex;
    align-items: center;
}
.status span {
    font-size: 12px;
}
.status .orange {
    color: #fe7234;
}
.status .blue {
    color: #2369ff;
}
</style>
